<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <!-- <a-col :span="24">
            <a-form-model-item label="专利分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="categoryId">
              <j-dict-select-tag type="list" v-model="model.categoryId" dictCode="ht_patent_category,name,id" placeholder="请选择专利分类" />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item
              label="供应专利名称"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="offerPatentName"
            >
              <a-input v-model="model.offerPatentName" placeholder="请输入供应专利名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="供应专利号"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="offerPatentNumber"
            >
              <a-input v-model="model.offerPatentNumber" placeholder="请输入供应专利号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="授权方式(0-普通许可，1-专利转让， 2-挂牌交易)"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="authorizationMethod"
            >
              <j-dict-select-tag
                type="list"
                v-model="model.authorizationMethod"
                dictCode="patent_authorization_method"
                placeholder="请选择授权方式(0-普通许可，1-专利转让， 2-挂牌交易)"
              />
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="供应报价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="offerPrice">
              <a-input-number v-model="model.offerPrice" placeholder="请输入供应报价,默认为商议" style="width: 100%" />
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="专利证书" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="patentCertificate">
              <j-image-upload isMultiple v-model="model.patentCertificate"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="专利证书"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="patentCertificate"
            >
              <j-image-upload :isMultiple="false" v-model="model.patentCertificate"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="其他资质"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="otherCertificates"
            >
              <j-image-upload isMultiple v-model="model.otherCertificates"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactPerson">
              <a-input v-model="model.contactPerson" placeholder="请输入联系人"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="联系人电话"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="contactPhoneNumber"
            >
              <a-input v-model="model.contactPhoneNumber" placeholder="请输入联系人电话"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea v-model="model.remark" rows="4" placeholder="请输入备注" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'HTPatentDemandOfferForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {
        offerPatentName: [{ required: true, message: '请输入供应专利名称!' }],
        offerPatentNumber: [{ required: true, message: '请输入供应专利号!' }],
        authorizationMethod: [{ required: true, message: '请输入授权方式(0-普通许可，1-普通许可)!' }],
        patentCertificate: [{ required: true, message: '请输入专利证书!' }],
        contactPerson: [{ required: true, message: '请输入联系人!' }],
        contactPhoneNumber: [
          { required: true, message: '请输入联系人电话!' },
          { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码' }
        ]
      },
      url: {
        add: '/patent/hTPatentDemandOffer/add',
        edit: '/patent/hTPatentDemandOffer/edit',
        queryById: '/patent/hTPatentDemandOffer/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      return new Promise((resolve, reject) => {
        that.$refs.form.validate(valid => {
          if (valid) {
            that.$emit('ok')
            resolve(that.model)
          }
        })
      })
    }
  }
}
</script>
